package com.dragon.www.smarthome.view.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.dragon.www.smarthome.R;
import com.dragon.www.smarthome.entity.Device;

/**
 * Created by daiye on 2016/6/2.
 */
public class DeviceEditDialog extends Dialog {
    private Context context;
    private Device device;

    private Button mLampBt;
    private Button mAirBt;
    private Button mCurtainBt;
    private Button mEntranceguardBt;
    private Button mHumidifierBt;
    private Button mPlantwallBt;

    public DeviceEditDialog(Context context) {
        super(context);
        this.context = context;
    }

    public DeviceEditDialog(Context context, int theme) {
        super(context, theme);
        this.context = context;
    }

    @Override
    protected final void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_add_device);
        mLampBt = (Button) findViewById(R.id.add_lamp_bt);
        mLampBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null)
                    listener.addLamp();
                dismiss();
            }
        });
        mAirBt = (Button) findViewById(R.id.add_air_bt);
        mAirBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null)
                    listener.addAir();
                dismiss();
            }
        });
        mCurtainBt = (Button) findViewById(R.id.add_curtain_bt);
        mCurtainBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null)
                    listener.addCurtain();
                dismiss();
            }
        });
        mEntranceguardBt = (Button) findViewById(R.id.add_entranceguard_bt);
        mEntranceguardBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null)
                    listener.addEntranceguard();
                dismiss();
            }
        });
        mHumidifierBt = (Button) findViewById(R.id.add_humidifier_bt);
        mHumidifierBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null)
                    listener.addHumidifier();
                dismiss();
            }
        });
        mPlantwallBt = (Button) findViewById(R.id.add_plantwall_bt);
        mPlantwallBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null)
                    listener.addPlantwall();
                dismiss();
            }
        });
    }

    @Override
    public void show() {
        if (context != null && ((Activity) context).isFinishing()) {
            return;
        }
        setCanceledOnTouchOutside(true);
        super.show();
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

    @Override
    public void setTitle(CharSequence title) {
        super.setTitle(title);
    }

    private OnSelectListener listener;

    public void setLisntener(OnSelectListener listener) {
        this.listener = listener;
    }

    public static abstract interface OnSelectListener {
        public abstract void addLamp();
        public abstract void addAir();
        public abstract void addCurtain();
        public abstract void addEntranceguard();
        public abstract void addHumidifier();
        public abstract void addPlantwall();
    }
}
